/*
 * Copyright (c) 2005 -2008 Reliable Source, Inc. and others.
 * All rights reserved. This program and the accompanying materials
 * are made available under the terms of the Mozilla Public License v.1.1,
 * BSD, and Eclipse Public License v1.0 which accompanies this
 * distribution and is available at:
 *
 * 		http://www.eclipse.org/legal/epl-v10.html
 * 		http://www.opensource.org/licenses/bsd-license.php
 * 		http://www.mozilla.org/MPL/MPL-1.1.html
 *
 * Contributors:
 *     IBM Corporation	     -  http://ibm.com
 *     	- initial API and implementation
 *
 *     patientos.org         - http://patientos.org
 *     	- domain and database persistence layer
 *
 *     Reliable Source, Inc. - http://reliablesource.org
 *     	- Symbiosys Application Framework,
 *     	- Symbiosys Application, Symbiosys Product
 *
 */
package org.reliablesource.symbiosys.workbench.tests;

import org.eclipse.core.runtime.IAdapterFactory;
import org.eclipse.core.runtime.IAdapterManager;
import org.eclipse.core.runtime.Platform;

import org.eclipse.ui.plugin.AbstractUIPlugin;

import org.osgi.framework.BundleContext;

import org.reliablesource.model.core.IReliableNode;

import org.reliablesource.symbiosys.workbench.tests.adapters.MockObjectAdapterFactory;


/**
 *
 * TestPlugin.java<br>
 * Created on: Jun 27, 2008<br>
 *
 * @author <a href="mailto:dennis.park@gmail.com">Dennis Park</a>
 *
 * @category
 * @since 1.0
 */
public class TestPlugin extends AbstractUIPlugin {
    public static final Object[] NULL_OBJECT = new Object[0];
    final static public String ID = "org.reliablesource.symbiosys.workbench.tests";

    // The shared instance.
    private static TestPlugin plugin;
    private IAdapterFactory adapterFactory;
    private IAdapterManager adapterManager;

    /**
     * The constructor.
     */
    public TestPlugin() {
        super();
        plugin = this;
    }

    /**
     * Returns the shared instance.
     */
    public static TestPlugin getDefault() {
        return plugin;
    }

    /*
     * (non-Javadoc)
     *
     * @see org.eclipse.ui.plugin.AbstractUIPlugin#start(org.osgi.framework.BundleContext)
     */
    @Override
    public void start(BundleContext context) throws Exception {
        super.start(context);
        adapterFactory = MockObjectAdapterFactory.getInstance();
        adapterManager = Platform.getAdapterManager();
        adapterManager.registerAdapters(adapterFactory, IReliableNode.class);
    }

    /*
     * (non-Javadoc)
     *
     * @see org.eclipse.ui.plugin.AbstractUIPlugin#stop(org.osgi.framework.BundleContext)
     */
    @Override
    public void stop(BundleContext context) throws Exception {
        adapterManager.unregisterAdapters(adapterFactory, IReliableNode.class);
        adapterManager = null;
        super.stop(context);
    }
}
